package com.motong.gongdan.vo.system.common.query;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Data
@Accessors(chain = true)
@ApiModel("id值通用请求")
public class IdValueQuery {

    @ApiModelProperty("属性ids(多个以,号隔开)")
    private String ids;

    @ApiModelProperty("属性值")
    private Object value;


    @ApiModelProperty(value = "idList", hidden = true)
    private List<String> idList = new ArrayList<>();

    @ApiModelProperty(value = "longIdList", hidden = true)
    private List<Long> longIdList = new ArrayList<>();

    /*逗号分隔格式化为数组*/
    public void setIds(String ids) {
        if (StringUtils.hasLength(ids)) {
            Arrays.asList(ids.split(",")).forEach(i -> {
                idList.add(i);
                try {
                    longIdList.add(Long.valueOf(i));
                } catch (Exception ignored) {

                }

            });
        }
        this.ids = ids;
    }

}
